home *** CD-ROM | disk | FTP | other *** search
- Subject: Re: Bug in FW_CStrings
- Sent: 7/25/96 4:20 PM
- Received: 7/25/96 3:41 PM
- From: Greg Friedman, friedman@cognosis.com
- Reply-To: ODF Interest, ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
-
- Kirk Swenson wrote:
- > There appears to be a bug in ODF's reference-counted string handling when
- > assigning from bounded strings (e.g. FW_CString32) to unbounded ones (e.g.
- > FW_CString). It took a while to isolate, and I haven't pinpointed it
- > exactly, but the following code demonstrates it:
-
- Kirk,
-
- Thanks for the work you've done to narrow this bug down. The code snippet
- you provided illustrates the minimum number of steps necessary to create
- the problem:
-
- 1. Allocate an unbounded/dynamic string.
- 2. Call a subroutine or enter a new block that does the following:
- a. Declare a bounded string.
- b. Assign the bounded string to the dynamic string.
- c. Assign new data to the bounded string.
- d. Exit the subroutine or current scope, causing the
- destructor of the bounded string to execute.
-
- The dynamic string is now corrupted or on the verge of corruption. The
- problem is caused by the fact that when the static string is assigned to
- the dynamic string (step b), the dynamic string acquires the static strings
- representation/buffer. This buffer is allocated as bytes on the stack. When
- new data is assigned to the bounded string, ODF clones the data, and
- assigns the new representation to the bounded string. The dynamic string is
- still using the stack-based buffer which is a data member of the bounded
- string. When the bounded string goes out of scope, the stack shrinks, and
- the dynamic string is left pointing at whatever unrelated stuff is in the
- stack space formerly occupied by the bounded string.
-
- The good news is that I've fixed the problem. The bad news is that the fix
- is in the shared library, and won't be released until ODF 2 ships. The fix
- alters the way that string representations are cloned. With the new
- implementation, the bounded string declared in the subroutine would have
- maintained ownership of its buffer, and the dynamic string would acquire
- the newly allocated buffer. Because we use double indirection, this will
- not have a negative impact on the case where there are more than 2 clients
- of a string representation.
-
- Until ODF 2 ships, I suggest you either use dynamic strings in all cases,
- or avoid the specific case you came across. Thanks again for taking the
- time to track the problem down.
-
- Greg Friedman.
- ODF Engineering.
-
-
- ___________________________________________________________
- Greg Friedman ODF Engineering Apple Computer
-
-
-